package xyz.xtt.user.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.user.entity.TblUserDeliveryAddress;
import xyz.xtt.user.request.UserAddressRequest;
import xyz.xtt.user.service.ITblUserDeliveryAddressService;

@Slf4j
@Schema(name = "用户地址", description = "用户地址")
@RequestMapping("/api/nft/user/address")
@RestController
public class UserAddressController {

	@Autowired
	private ITblUserDeliveryAddressService userAddressService;

	// 获取用户所有地址
	@Operation(summary = "获取用户所有地址")
	@GetMapping("/getUserAddress")
	public ApiResult<List<TblUserDeliveryAddress>> getUserAddress(@RequestHeader("uid") String uid) {
		log.info("/api/address/getUserAddress userId:{}", uid);
		List<TblUserDeliveryAddress> userAddress = userAddressService.getUserAddress(uid);
		return ApiResult.ok(userAddress);
	}

	// 获取用户所有地址
	@Operation(summary = "新增用户所有地址")
	@PostMapping("/addUserAddress")
	public ApiResult<?> addUserAddress(@RequestHeader("uid") String uid, @RequestBody @Validated UserAddressRequest userAddress) {
		log.info("/api/address/addUserAddress userId:{}", uid);
		return userAddressService.addUserAddress(uid, userAddress);
	}

}
